import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutterdemo/0demo/main_page.dart';
import 'package:flutterdemo/0demo/ui/custom_charts/custom_charts.dart';

void main() {
  testWidgets("app jump test", (WidgetTester tester) async {
    await tester.pumpWidget(MaterialApp(
      home: MainPage(),
    ));
    final list = find.byType(ListView);
    // 列表的话，越屏找不到对应的widget，需要将要找的widget滑动到屏幕内
    // await tester.drag(list, Offset(0, -3000));
    // await tester.pumpAndSettle();
    final btn = find.text("custom charts test");
    // Scroll until the item to be found appears.
    // 只有一个滑动组件Scrollable可以不填写，delta是正数才行，repeat scroll by delta
    await tester.scrollUntilVisible(
      btn,
      100.0,
    );

    await tester.tap(btn);
    await tester.pumpAndSettle();

    // 如果是CustomPaint paint出的text，其实不是text widget，所以找不到该widget
    expect(find.text('111'), findsNWidgets(1));
    expect(find.text('222'), findsNWidgets(1));
    expect(find.text('custom charts'), findsNWidgets(1));
    expect(find.byType(CustomCharts), findsNWidgets(1));
  });
}
